<template>
  <div class="process-route-container">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <span>首页</span>
      <span class="separator">/</span>
      <span>工艺路线</span>
      <el-icon class="close-icon" @click="$router.go(-1)"><Close /></el-icon>
    </div>

    <!-- 标题 -->
    <div class="page-title">
      <el-icon><Grid /></el-icon>
      <span>工艺路线</span>
    </div>

    <!-- 第一表格：工艺路线 -->
    <div class="main-table">
      <div class="table-header">
        <el-icon><Grid /></el-icon>
        <span>工艺路线</span>
      </div>

      <!-- 搜索和操作区域 -->
      <div class="search-action-bar">
        <div class="search-fields">
          <el-input
            v-model="searchForm.processRouteCode"
            placeholder="工艺路线编号"
            clearable
            style="width: 200px; margin-right: 10px;"
          />
          <el-input
            v-model="searchForm.processRouteName"
            placeholder="工艺路线名称"
            clearable
            style="width: 200px; margin-right: 10px;"
          />
          <el-select
            v-model="searchForm.enableApproval"
            placeholder="开启审批"
            clearable
            style="width: 150px; margin-right: 10px;"
          >
            <el-option label="是" :value="true" />
            <el-option label="否" :value="false" />
          </el-select>
        </div>
        <div class="action-buttons">
          <el-button type="primary" @click="handleSearch">
            <el-icon><Search /></el-icon>
            查询
          </el-button>
          <el-button type="success" @click="handleAdd">
            <el-icon><Plus /></el-icon>
            新建
          </el-button>
          <el-button type="primary" @click="handleEdit" :disabled="!selectedRow">
            <el-icon><Edit /></el-icon>
            编辑
          </el-button>
          <el-button type="danger" @click="handleDelete" :disabled="!selectedRow">
            <el-icon><Delete /></el-icon>
            删除
          </el-button>
        </div>
      </div>

      <!-- 工艺路线表格 -->
      <el-table
        :data="processRouteList"
        @row-click="handleRowClick"
        @selection-change="handleSelectionChange"
        highlight-current-row
        :row-class-name="getRowClassName"
        style="width: 100%"
        v-loading="loading"
      >
        <el-table-column type="selection" width="60" />
        <el-table-column type="index" label="#" width="60" />
        <el-table-column prop="routeCode" label="工艺路线编号" width="280" sortable />
        <el-table-column prop="routeName" label="工艺路线名称" width="220" sortable />
        <el-table-column prop="needApproval" label="开启审批" width="120">
          <template #default="scope">
            <el-tag v-if="scope.row.needApproval" type="success" size="small">是</el-tag>
            <el-tag v-else type="info" size="small">否</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="200" sortable>
          <template #default="scope">
            {{ scope.row.createTime ? new Date(scope.row.createTime).toLocaleString() : '-' }}
          </template>
        </el-table-column>
        <el-table-column prop="creator" label="创建人" width="120" />
        <el-table-column prop="modifier" label="修改人" width="120">
          <template #default="scope">
            {{ scope.row.modifier || '-' }}
          </template>
        </el-table-column>
        <el-table-column prop="modifyTime" label="修改时间" width="200" sortable>
          <template #default="scope">
            {{ scope.row.modifyTime ? new Date(scope.row.modifyTime).toLocaleString() : '-' }}
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          v-model:current-page="pagination.pageIndex"
          v-model:page-size="pagination.pageSize"
          :page-sizes="[10, 20, 30, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <!-- 第二表格：工艺路线-工序列表 -->
    <div class="sub-table">
      <div class="table-header">
        <el-icon><Grid /></el-icon>
        <span>工艺路线-工序列表 - {{ selectedRow ? selectedRow.routeName : '请选择工艺路线' }}</span>
        <span v-if="selectedRow" class="selected-info">
          (共 {{ operationList.length }} 项工序)
        </span>
      </div>
      
      <el-table :data="operationList" style="width: 100%" v-loading="subLoading">
        <template #empty>
          <div class="empty-state">
            <el-icon size="48" color="#c0c4cc"><Grid /></el-icon>
            <p v-if="!selectedRow">请先选择上方的工艺路线</p>
            <p v-else-if="operationList.length === 0">该工艺路线暂无关联的工序</p>
            <p v-else>暂无数据</p>
          </div>
        </template>
        <el-table-column type="selection" width="60" />
        <el-table-column type="index" label="#" width="60" />
        <el-table-column prop="processRouteName" label="工艺路线" width="180" />
        <el-table-column prop="itemType" label="类型" width="120" sortable>
          <template #default="scope">
            <el-tag v-if="scope.row.itemType" size="small" type="warning">
              {{ scope.row.itemType }}
            </el-tag>
            <span v-else class="no-data">-</span>
          </template>
        </el-table-column>
        <el-table-column prop="workProcessName" label="工序" width="180">
          <template #default="scope">
            <el-tag v-if="scope.row.workProcessName" size="small" type="success">
              {{ scope.row.workProcessName }}
            </el-tag>
            <span v-else class="no-data">-</span>
          </template>
        </el-table-column>
        <el-table-column prop="subProcessRouteName" label="子工艺路线" width="180" />
        <el-table-column prop="processRatio" label="报工数配比" width="120" />
        <el-table-column prop="sortOrder" label="排序" width="80" />
        <el-table-column prop="createTime" label="创建时间" width="200" sortable>
          <template #default="scope">
            {{ scope.row.createTime ? new Date(scope.row.createTime).toLocaleString() : '-' }}
          </template>
        </el-table-column>
        <el-table-column prop="creator" label="创建人" width="120" />
      </el-table>
    </div>

    <!-- 新建/编辑对话框 -->
    <el-dialog
      v-model="dialogVisible"
      :title="dialogTitle"
      width="90%"
      :before-close="handleDialogClose"
    >
      <el-form
        ref="formRef"
        :model="form"
        :rules="rules"
        label-width="120px"
        class="process-route-form"
      >
        <div class="form-row">
          <el-form-item label="工艺路线编号" prop="routeCode">
            <div class="code-input-group">
              <el-input
                v-model="form.routeCode"
                placeholder="工艺路线编号"
                :disabled="isEdit"
              />
              <el-button 
                v-if="!isEdit"
                type="primary" 
                size="small" 
                @click="regenerateRouteCode"
                style="margin-left: 8px;"
              >
                重新生成
              </el-button>
            </div>
            <div class="code-tip" v-if="!isEdit">
              格式：GYLX + 年月日时分秒 + 3位随机数
            </div>
          </el-form-item>
          <el-form-item label="工艺路线名称" prop="routeName">
            <el-input
              v-model="form.routeName"
              placeholder="工艺路线名称"
            />
          </el-form-item>
        </div>

        <div class="form-row">
          <el-form-item label="开启审批" prop="needApproval">
            <el-switch
              v-model="form.needApproval"
              active-text="是"
              inactive-text="否"
            />
          </el-form-item>
        </div>

        <!-- 工序列表 -->
        <div class="process-items-section">
          <div class="section-header">
            <h3>工序列表</h3>
            <el-button type="primary" size="small" @click="addProcessItem">
              <el-icon><Plus /></el-icon>
              添加工序
            </el-button>
          </div>
          
          <el-table :data="form.processItems" style="width: 100%">
            <el-table-column type="index" label="#" width="80" />
            <el-table-column label="类型" width="150">
              <template #default="scope">
                <el-select v-model="scope.row.itemType" placeholder="选择类型" style="width: 100%">
                  <el-option label="工序" value="工序" />
                  <el-option label="工艺路线" value="工艺路线" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="工序/工艺路线" width="300">
              <template #default="scope">
                <el-select 
                  v-model="scope.row.workProcessId" 
                  placeholder="选择工序"
                  style="width: 100%"
                  v-if="scope.row.itemType === '工序'"
                  filterable
                  clearable
                  :loading="workProcessLoading"
                  @change="handleWorkProcessChange(scope.$index, $event)"
                >
                  <el-option 
                    v-for="item in workProcessOptions" 
                    :key="item.workProcessId" 
                    :label="`${item.processCode} - ${item.processName}`" 
                    :value="item.workProcessId" 
                  >
                    <span style="float: left">{{ item.processCode }}</span>
                    <span style="float: right; color: #8492a6; font-size: 13px">{{ item.processName }}</span>
                  </el-option>
                </el-select>
                <el-select 
                  v-model="scope.row.subProcessRouteId" 
                  placeholder="选择工艺路线"
                  style="width: 100%"
                  v-else-if="scope.row.itemType === '工艺路线'"
                  filterable
                  clearable
                  :loading="processRouteLoading"
                  @change="handleProcessRouteChange(scope.$index, $event)"
                >
                  <el-option 
                    v-for="item in processRouteOptions" 
                    :key="item.processRouteId" 
                    :label="`${item.routeCode} - ${item.routeName}`" 
                    :value="item.processRouteId" 
                  >
                    <span style="float: left">{{ item.routeCode }}</span>
                    <span style="float: right; color: #8492a6; font-size: 13px">{{ item.routeName }}</span>
                  </el-option>
                </el-select>
                <div v-else class="no-data">请先选择类型</div>
              </template>
            </el-table-column>
            <el-table-column label="报工数配比" width="150">
              <template #default="scope">
                <el-input-number 
                  v-model="scope.row.processRatio" 
                  :min="0.1" 
                  :max="100" 
                  :precision="2"
                  style="width: 100%"
                />
              </template>
            </el-table-column>
            <el-table-column label="排序" width="120">
              <template #default="scope">
                <el-input-number 
                  v-model="scope.row.sortOrder" 
                  :min="1" 
                  :max="999"
                  style="width: 100%"
                />
              </template>
            </el-table-column>
            <el-table-column label="操作" width="120">
              <template #default="scope">
                <el-button 
                  type="danger" 
                  size="small" 
                  @click="removeProcessItem(scope.$index)"
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleSubmit" :loading="submitLoading">
            <el-icon><Check /></el-icon>
            保存
          </el-button>
          <el-button @click="handleDialogClose">
            <el-icon><Close /></el-icon>
            关闭
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, computed } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  Search, Plus, Edit, Delete, Upload, Download, Grid, Close, Check
} from '@element-plus/icons-vue'
import { MES_XSP_ApiHost } from '@/utils/Interceptors'

// 响应式数据
const processRouteList = ref([])
const operationList = ref([])
const selectedRow = ref(null)
const selectedRows = ref([])
const dialogVisible = ref(false)
const isEdit = ref(false)
const formRef = ref()
const loading = ref(false)
const subLoading = ref(false)
const submitLoading = ref(false)
const workProcessLoading = ref(false)
const processRouteLoading = ref(false)

// 选项数据
const workProcessOptions = ref([])
const processRouteOptions = ref([])

// 搜索表单
const searchForm = reactive({
  processRouteCode: '',
  processRouteName: '',
  enableApproval: null
})

// 分页数据
const pagination = reactive({
  pageIndex: 1,
  pageSize: 30,
  total: 0
})

// 表单数据
const form = reactive({
  routeCode: '',
  routeName: '',
  needApproval: false,
  processItems: []
})

// 表单验证规则
const rules = {
  routeName: [
    { required: true, message: '请输入工艺路线名称', trigger: 'blur' }
  ]
}

// 计算属性
const dialogTitle = computed(() => {
  return isEdit.value ? '工艺路线 (编辑)' : '工艺路线 (新建)'
})

// 方法
const fetchData = async () => {
  try {
    loading.value = true
    const params = {
      processRouteCode: searchForm.processRouteCode || null,
      processRouteName: searchForm.processRouteName || null,
      enableApproval: searchForm.enableApproval,
      pageIndex: pagination.pageIndex,
      pageSize: pagination.pageSize
    }
    
    const response = await MES_XSP_ApiHost.get('/api/ProcessRouteGetProcessRouteList', { params })
    console.log('工艺路线列表API响应:', response.data);
    
    if (response.data.code === 200) {
      processRouteList.value = response.data.pageData
      pagination.total = response.data.totalCount
    } else {
      ElMessage.error(response.data.msg || '获取数据失败')
    }
  } catch (error) {
    console.error('获取工艺路线列表失败:', error)
    ElMessage.error('获取数据失败')
  } finally {
    loading.value = false
  }
}

const fetchOperationList = async (processRouteId) => {
  if (!processRouteId) {
    operationList.value = []
    return
  }
  
  try {
    subLoading.value = true
    console.log('获取工艺路线详情，ID:', processRouteId)
    
    const response = await MES_XSP_ApiHost.get('/api/ProcessRouteGetProcessRouteById', {
      params: { id: processRouteId }
    })
    
    console.log('工艺路线详情API响应:', response.data)
    
    if (response.data.code === 200) {
      operationList.value = response.data.data?.processItems || []
      console.log('获取到的工序列表:', operationList.value)
    } else {
      console.error('获取工艺路线详情失败:', response.data.msg)
      ElMessage.error(response.data.msg || '获取工艺路线详情失败')
      operationList.value = []
    }
  } catch (error) {
    console.error('获取工艺路线详情失败:', error)
    ElMessage.error('获取工艺路线详情失败')
    operationList.value = []
  } finally {
    subLoading.value = false
  }
}

const fetchWorkProcessOptions = async () => {
  try {
    workProcessLoading.value = true
    const response = await MES_XSP_ApiHost.get('/api/ProcessRouteGetAllWorkProcesses')
    console.log('获取工序选项API响应:', response.data)
    
    if (response.data.code === 200) {
      workProcessOptions.value = response.data.data || []
      console.log('工序选项数据:', workProcessOptions.value)
    } else {
      console.error('获取工序选项失败:', response.data.msg)
      ElMessage.warning('获取工序选项失败: ' + response.data.msg)
    }
  } catch (error) {
    console.error('获取工序选项失败:', error)
    ElMessage.error('获取工序选项失败')
  } finally {
    workProcessLoading.value = false
  }
}

const fetchProcessRouteOptions = async () => {
  try {
    processRouteLoading.value = true
    const response = await MES_XSP_ApiHost.get('/api/ProcessRouteGetProcessRouteList', {
      params: { pageSize: 1000 }
    })
    console.log('获取工艺路线选项API响应:', response.data)
    
    if (response.data.code === 200) {
      processRouteOptions.value = response.data.pageData || []
      console.log('工艺路线选项数据:', processRouteOptions.value)
    } else {
      console.error('获取工艺路线选项失败:', response.data.msg)
      ElMessage.warning('获取工艺路线选项失败: ' + response.data.msg)
    }
  } catch (error) {
    console.error('获取工艺路线选项失败:', error)
    ElMessage.error('获取工艺路线选项失败')
  } finally {
    processRouteLoading.value = false
  }
}

const handleSearch = () => {
  pagination.pageIndex = 1
  fetchData()
}

const handleAdd = async () => {
  isEdit.value = false
  resetForm()
  
  // 自动生成工艺路线编号
  form.routeCode = generateRouteCode()
  console.log('新建工艺路线，自动生成编号:', form.routeCode)
  
  // 确保选项数据已加载
  if (workProcessOptions.value.length === 0) {
    await fetchWorkProcessOptions()
  }
  if (processRouteOptions.value.length === 0) {
    await fetchProcessRouteOptions()
  }
  
  dialogVisible.value = true
}

const handleEdit = async () => {
  if (!selectedRow.value) {
    ElMessage.warning('请先选择要编辑的行')
    return
  }
  
  try {
    const response = await MES_XSP_ApiHost.get('/api/ProcessRouteGetProcessRouteById', {
      params: { id: selectedRow.value.processRouteId }
    })
    
    if (response.data.code === 200) {
      const data = response.data.data
      loadFormData(data)
      isEdit.value = true
      dialogVisible.value = true
    } else {
      ElMessage.error(response.data.msg || '获取详情失败')
    }
  } catch (error) {
    console.error('获取详情失败:', error)
    ElMessage.error('获取详情失败')
  }
}

const handleDelete = async () => {
  if (!selectedRow.value) {
    ElMessage.warning('请先选择要删除的行')
    return
  }
  
  try {
    await ElMessageBox.confirm('确定要删除选中的工艺路线吗？', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    
    const response = await MES_XSP_ApiHost.delete('/api/ProcessRouteDeleteProcessRoute', {
      params: { id: selectedRow.value.processRouteId }
    })
    
    if (response.data.code === 200) {
      ElMessage.success('删除成功')
      fetchData()
      selectedRow.value = null
      operationList.value = []
    } else {
      ElMessage.error(response.data.msg || '删除失败')
    }
  } catch (error) {
    if (error !== 'cancel') {
      console.error('删除失败:', error)
      ElMessage.error('删除失败')
    }
  }
}

const handleRowClick = (row) => {
  console.log('点击工艺路线行:', row)
  selectedRow.value = row
  
  // 清空之前的工序列表
  operationList.value = []
  
  // 获取关联的工序列表
  fetchOperationList(row.processRouteId)
  
  // 显示选中提示
  ElMessage.success(`已选择工艺路线: ${row.routeName}`)
}

const getRowClassName = ({ row }) => {
  if (selectedRow.value && row.processRouteId === selectedRow.value.processRouteId) {
    return 'selected-row'
  }
  return ''
}

const handleSelectionChange = (selection) => {
  selectedRows.value = selection
}

const handleSizeChange = (size) => {
  pagination.pageSize = size
  fetchData()
}

const handleCurrentChange = (page) => {
  pagination.pageIndex = page
  fetchData()
}

// 生成工艺路线编号
const generateRouteCode = () => {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hour = String(now.getHours()).padStart(2, '0')
  const minute = String(now.getMinutes()).padStart(2, '0')
  const second = String(now.getSeconds()).padStart(2, '0')
  
  // 生成3位随机数
  const randomNum = Math.floor(Math.random() * 900) + 100 // 100-999
  
  const routeCode = `GYLX${year}${month}${day}${hour}${minute}${second}${randomNum}`
  console.log('生成的工艺路线编号:', routeCode)
  return routeCode
}

const addProcessItem = () => {
  const newItem = {
    itemType: '工序',
    workProcessId: null,
    subProcessRouteId: null,
    processRatio: 1,
    sortOrder: form.processItems.length + 1
  }
  form.processItems.push(newItem)
  console.log('添加工序项:', newItem)
  console.log('当前工序列表:', form.processItems)
}

const removeProcessItem = (index) => {
  form.processItems.splice(index, 1)
  // 重新排序
  form.processItems.forEach((item, idx) => {
    item.sortOrder = idx + 1
  })
}

const handleWorkProcessChange = (index, value) => {
  console.log(`工序选择变化 - 索引: ${index}, 值: ${value}`)
  if (value) {
    const selectedProcess = workProcessOptions.value.find(item => item.workProcessId === value)
    if (selectedProcess) {
      console.log('选中的工序:', selectedProcess)
    }
  }
}

const handleProcessRouteChange = (index, value) => {
  console.log(`工艺路线选择变化 - 索引: ${index}, 值: ${value}`)
  if (value) {
    const selectedRoute = processRouteOptions.value.find(item => item.processRouteId === value)
    if (selectedRoute) {
      console.log('选中的工艺路线:', selectedRoute)
    }
  }
}

// 防抖函数
const debounce = (func, wait) => {
  let timeout
  return function executedFunction(...args) {
    const later = () => {
      clearTimeout(timeout)
      func(...args)
    }
    clearTimeout(timeout)
    timeout = setTimeout(later, wait)
  }
}

const regenerateRouteCode = debounce(() => {
  form.routeCode = generateRouteCode()
  ElMessage.success('工艺路线编号已重新生成')
}, 300)

const resetForm = () => {
  Object.assign(form, {
    routeCode: '',
    routeName: '',
    needApproval: false,
    processItems: []
  })
}

const loadFormData = (data) => {
  Object.assign(form, {
    routeCode: data.routeCode,
    routeName: data.routeName,
    needApproval: data.needApproval,
    processItems: data.processItems || []
  })
}

const handleSubmit = async () => {
  try {
    await formRef.value.validate()
    submitLoading.value = true
    
    const submitData = {
      routeCode: form.routeCode,
      routeName: form.routeName,
      needApproval: form.needApproval,
      creator: 'Admin',
      processItems: form.processItems
    }
    
    let response
    if (isEdit.value) {
      response = await MES_XSP_ApiHost.put('/api/ProcessRouteUpdateProcessRoute', submitData, {
        params: { id: selectedRow.value.processRouteId }
      })
    } else {
      response = await MES_XSP_ApiHost.post('/api/ProcessRouteCreateProcessRoute', submitData)
    }
    
    if (response.data.code === 200) {
      ElMessage.success(isEdit.value ? '更新成功' : '创建成功')
      dialogVisible.value = false
      fetchData()
      if (selectedRow.value) {
        fetchOperationList(selectedRow.value.processRouteId)
      }
    } else {
      ElMessage.error(response.data.msg || '操作失败')
    }
  } catch (error) {
    console.error('提交失败:', error)
    ElMessage.error('提交失败')
  } finally {
    submitLoading.value = false
  }
}

const handleDialogClose = () => {
  dialogVisible.value = false
  resetForm()
}

// 生命周期
onMounted(async () => {
  await fetchData()
  await fetchWorkProcessOptions()
  await fetchProcessRouteOptions()
  
  // 调试信息
  console.log('页面初始化完成')
  console.log('工序选项数量:', workProcessOptions.value.length)
  console.log('工艺路线选项数量:', processRouteOptions.value.length)
})
</script>

<style scoped>
.process-route-container {
  padding: 15px;
  background-color: #f5f5f5;
  min-height: 100vh;
}

.breadcrumb {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  color: #666;
}

.separator {
  margin: 0 6px;
  color: #ccc;
}

.close-icon {
  margin-left: auto;
  cursor: pointer;
  color: #999;
}

.close-icon:hover {
  color: #409eff;
}

.page-title {
  display: flex;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 15px;
  color: #333;
}

.page-title .el-icon {
  margin-right: 8px;
  font-size: 20px;
}

.main-table, .sub-table {
  background: white;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.table-header {
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 12px;
  color: #333;
}

.table-header .el-icon {
  margin-right: 6px;
}

.selected-info {
  margin-left: 10px;
  color: #409eff;
  font-size: 13px;
  font-weight: normal;
}

.search-action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding: 12px;
  background-color: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e9ecef;
}

.search-fields {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-buttons {
  display: flex;
  gap: 6px;
}

.action-buttons .el-button {
  padding: 6px 12px;
  font-size: 12px;
}

.pagination {
  display: flex;
  justify-content: center;
  margin-top: 15px;
  padding: 12px;
  background-color: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e9ecef;
}

/* 分页组件样式 */
:deep(.el-pagination) {
  font-size: 13px;
}

:deep(.el-pagination .el-pager li) {
  border-radius: 3px;
  margin: 0 1px;
}

:deep(.el-pagination .el-pager li.is-active) {
  background-color: #409eff;
  color: white;
}

.no-data {
  color: #909399;
  font-style: italic;
  text-align: center;
  padding: 10px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #909399;
}

.empty-state .el-icon {
  margin-bottom: 16px;
}

.empty-state p {
  margin: 0;
  font-size: 14px;
}

/* 下拉框选项样式 */
:deep(.el-select-dropdown__item) {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

:deep(.el-select-dropdown__item span) {
  flex: 1;
}

/* 工序表格样式 */
.process-items-section {
  margin-top: 15px;
  border-top: 1px solid #eee;
  padding-top: 15px;
}

.process-items-section .el-table {
  margin-top: 8px;
  width: 100%;
}

/* 对话框表格样式优化 */
:deep(.el-dialog) {
  max-width: 95vw;
}

:deep(.el-dialog__body) {
  padding: 20px;
}

/* 确保表格占满宽度 */
:deep(.el-table) {
  table-layout: fixed;
}

:deep(.el-table__body-wrapper) {
  overflow-x: auto;
}

/* 表格单元格内容样式 */
:deep(.el-table .cell) {
  word-break: break-all;
  white-space: normal;
}

/* 下拉框在表格中的样式 */
:deep(.el-table .el-select) {
  width: 100%;
}

:deep(.el-table .el-input-number) {
  width: 100%;
}

/* 加载状态样式 */
:deep(.el-select .el-loading-mask) {
  background-color: rgba(255, 255, 255, 0.8);
}

/* 编号输入组样式 */
.code-input-group {
  display: flex;
  align-items: center;
}

.code-tip {
  font-size: 12px;
  color: #909399;
  margin-top: 4px;
  line-height: 1.4;
}

/* 重新生成按钮样式 */
.code-input-group .el-button {
  flex-shrink: 0;
  height: 32px;
  border-radius: 4px;
}

.process-route-form {
  max-height: 70vh;
  overflow-y: auto;
  width: 100%;
}

.form-row {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
}

.form-row .el-form-item {
  flex: 1;
}

.process-items-section {
  margin-top: 20px;
  border-top: 1px solid #eee;
  padding-top: 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-header h3 {
  margin: 0;
  color: #333;
  font-size: 14px;
}

.dialog-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.dialog-footer .el-button {
  min-width: 80px;
}

/* 表格样式优化 */
:deep(.el-table) {
  border-radius: 8px;
  overflow: hidden;
  font-size: 14px;
}

:deep(.el-table th) {
  background-color: #f8f9fa;
  color: #495057;
  font-weight: 600;
  font-size: 12px;
  padding: 8px 6px;
  border-bottom: 2px solid #e9ecef;
}

:deep(.el-table td) {
  padding: 6px 6px;
  border-bottom: 1px solid #f0f0f0;
}

:deep(.el-table tr:hover > td) {
  background-color: #f8f9fa;
}

/* 选中行样式 */
:deep(.selected-row) {
  background-color: #e6f7ff !important;
}

:deep(.selected-row td) {
  background-color: #e6f7ff !important;
}

:deep(.selected-row:hover td) {
  background-color: #bae7ff !important;
}

/* 表格内容对齐 */
:deep(.el-table .cell) {
  text-align: center;
}

:deep(.el-table .el-table__cell:first-child .cell) {
  text-align: center;
}

/* 标签样式优化 */
:deep(.el-tag) {
  border-radius: 3px;
  font-weight: 500;
  font-size: 11px;
  padding: 1px 6px;
}

/* 按钮样式 */
:deep(.el-button) {
  border-radius: 6px;
  font-weight: 500;
}

:deep(.el-button--primary) {
  background: linear-gradient(135deg, #409eff, #337ecc);
  border: none;
}

:deep(.el-button--success) {
  background: linear-gradient(135deg, #67c23a, #5daf34);
  border: none;
}

:deep(.el-button--danger) {
  background: linear-gradient(135deg, #f56c6c, #e74c3c);
  border: none;
}

/* 输入框样式 */
:deep(.el-input__wrapper) {
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* 标签样式 */
:deep(.el-tag) {
  border-radius: 4px;
  font-weight: 500;
}
</style>

